package webservice;

import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.junit.Test;

public class CxfClient
{


    @Test
    public void main2()
    {
        try
        {
            String address = "http://192.168.1.7/file/webservice?wsdl";
            JaxWsProxyFactoryBean jaxWsProxyFactoryBean = new JaxWsProxyFactoryBean();

            jaxWsProxyFactoryBean.setAddress(address);
            jaxWsProxyFactoryBean.setServiceClass(String.class);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    @Test
    public  void main1()
    {
        JaxWsDynamicClientFactory jw = JaxWsDynamicClientFactory.newInstance();

        Client client = jw.createClient("http://localhost:8090/services/api?wsdl");
        Object[] objects = new Object[0];
        //client.getOutInterceptors().add(new LoginInterceptor("admin","admin123"));
        try
        {
            objects = client.invoke("test","key", "测试参数");
            System.out.println("返回数据"+objects[0]);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    @Test
    public void test2()
    {
        JaxWsDynamicClientFactory jw = JaxWsDynamicClientFactory.newInstance();

        Client client = jw.createClient("http://localhost:8999/?wsdl");
        Object[] objects = new Object[0];
        try
        {
            objects = client.invoke("mul",5.0,2.0);
            System.out.println("返回数据"+objects[0]);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}
